package st.business.tepth.business.user;

import st.business.tepth.base.OnDataConvertListener;
import st.business.tepth.business.bean.LocationBean;

/**
 * @author zhangyu
 * @date 2019/3/6
 */
public class UserPresenter extends UserContract.Presenter {
    private final UserContract.View mView;
    private final UserContract.Model mModel;

    public UserPresenter(UserContract.View view) {
        mView = view;
        mModel = new UserModel();
    }

    @Override
    void getLocationInfo(String id, String token) {
        addDisposable(mModel.getLocationInfo(id, token, new OnDataConvertListener<LocationBean>() {
            @Override
            public void convert(LocationBean locationBean) {
                if (mView != null) {
                    mView.showLocationInfo(locationBean);
                }
            }

            @Override
            public void error(int code, String msg) {
                if (mView != null) {
                    mView.showLocationInfo(null);
                }
            }
        }));
    }

    @Override
    void offWork(String token) {
        addDisposable(mModel.offWork(token,
                new OnDataConvertListener<String>() {
                    @Override
                    public void convert(String response) {
                        if (mView != null) {
                            mView.offWorkSucceed();
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.showError(msg);
                        }
                    }
                }));
    }
}
